<template>
    <el-container class="home_container">
        <el-header>
            <div>
                <img src="../assets/admin/image/mandarinlogo.png" width = "150px" height = "70px" alt="">
            </div>
            <span>LibraryAdmin Register</span>
            <el-button type="info">BACK</el-button>
        </el-header>
        <el-main>
            <div class="register_box">
            <div class="avatar_box">
                <img src="../assets/admin/image/registrationlogo.png" alt="">
            </div>
            <!-- 注册表单区域 -->
            <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="90px" class="register_form">
                <!-- 用户名 -->
                <el-form-item prop="name" label="Username:">
                    <el-input v-model='loginForm.name' prefix-icon="el-icon-user-solid" placeholder="At least 3 characters"></el-input>
                </el-form-item>
                <!-- 密码 -->
                <el-form-item prop="pwd" label="Password:">
                    <el-input v-model='loginForm.pwd' prefix-icon="el-icon-lock" show-password placeholder="At least 6 characters"></el-input>
                </el-form-item>
                 <!-- 确认密码 -->
                <el-form-item prop="pwdRep" label="Confirm:">
                    <el-input v-model='loginForm.pwdRep' prefix-icon="el-icon-star-on" show-password placeholder="Confirm your password"></el-input>
                </el-form-item>
                <!-- 电话 -->
                <!-- <el-form-item prop="phonenum" label="Telephone:"> -->
                    <!-- <el-input v-model='loginForm.phonenum' prefix-icon="el-icon-phone" placeholder="Enter your phone number"></el-input> -->
                <!-- </el-form-item>
                <! 邮箱 -->
                <!-- <el-form-item prop="email" label="Email:"> -->
                    <!-- <el-input v-model='loginForm.email' prefix-icon="el-icon-message" placeholder="Enter your email address"> -->
                      <!-- <template slot="append">.com</template> -->
                    <!-- </el-input> -->
                <!-- </el-form-item> -->
                <!-- 按钮区域 -->
                <el-form-item class="btns">
                    <el-button type="primary" @click="register">Register</el-button>
                    <el-button type="info" @click="resetLoginForm">Reset</el-button>
                </el-form-item>
            </el-form>
        </div>
        </el-main>
    </el-container>
</template>

<script>
export default {
  data () {
    return {
    // 这是登陆表单的数据绑定对象
      loginForm: {
        name: '',
        pwd: '',
        pwdRep: ''
      },
      //   表单的验证规则对象
      loginFormRules: {
        //   验证用户名是否合法
        name: [
          { required: true, message: 'Please set your account', trigger: 'blur' },
          { min: 3, max: 15, message: 'At least 3 characters', trigger: 'blur' }
        ],
        //   验证密码是否合法
        pwd: [
          { required: true, message: 'Please set your password', trigger: 'blur' },
          { min: 6, max: 15, message: 'At least 6 characters', trigger: 'blur' }
        ],
        pwdRep: [
          { required: true, message: 'Please ensure that the two entries are the same', trigger: 'blur' }
        ]
        // phonenum: [
        //   { required: true, message: 'Please enter your phone number', trigger: 'blur' }
        // ],
        // email: [
        //   { required: true, message: 'Please enter your email', trigger: 'blur' }
        // ]
      }
    }
  },
  methods: {
    //   点击重置按钮，重置登录表单
    resetLoginForm () {
      this.$refs.loginFormRef.resetFields()
    },
    register () {
      this.$refs.loginFormRef.validate(async valid => {
        const { data: ces } = await this.$http.get('https://118.178.190.4/admin/login?name=admin&password=admin')
        console.log(ces)
        if (!valid) return
        const { data: res } = await this.$http.post('https:/118.178.190.4/admin/bookmanager?name=' + this.loginForm.name + '&pwd=' + this.loginForm.pwd + '&pwdRep=' + this.loginForm.pwdRep)
        console.log(res)
        if (res.errorCode !== 0) return this.$message.error('Registration failed!')
        this.$message.success('Registration success!')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.home_container{
    height: 100%;
}

.el-header {
    background-color: #808080;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items:center;
    font-size: 30px;
}

// .el-main {
// }

.register_box {
    width: 450px;
    height: 365px;
    background-color: #D3D3D3;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 57%;
    transform: translate(-50%, -50%);

    .avatar_box{
        height: 130px;
        width: 130px;
        border: 1px solid #eee;
        border-radius: 50%;
        padding: 10px;
        box-shadow: 0 0 10px #ddd;
        position: absolute;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: #fff;
        img{
            width: 100%;
            height: 100;
            border-radius: 50%;
        }
    }
}

.register_form {
    position: absolute;
    bottom: 4px;
    width: 90%;
    padding-left: 10px;
    // box-sizing: border-box;
}

.btns {
    display: flex;
    justify-content: flex-end;
}
</style>
